<template>
    <!-- 推广收益 -->
    <div style="overflow:scroll">
        <mt-loadmore :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" ref="loadmore" :bottomDistance=bottomDistance>
            <ul class="m_t20 content">
                <li class="generalize-item m_b20" v-for="item in genaralizeList">
                    <div
                        class="uname-price flex flex-pack-justify color_33 font_size28 flex-align-center"
                    >
                        <span>来自:{{item.username}}</span>
                        <span class="color_fc">￥{{Number(item.balance).toFixed(2)}}</span>
                    </div>
                    <div class="title-count-time bg_colorff">
                        <p
                            class="font_size32 font-bold m_b20"
                        >{{item.name.length>14?item.name.substring(0,14)+'...':item.name}}</p>
                        <p class="font_size24 color_99 count">购买数量:{{item.goods_num}}</p>
                        <p class="font_size24 color_99">补贴时间:{{item.create_time | DateFomate}}</p>
                    </div>
                </li>
            </ul>
        </mt-loadmore>
    </div>
</template>

<script>
export default {
  data() {
    return {
      genaralizeList: [],
      pagesNum: 1, //当前页数
      maxPageNum: 0, //最大页数
      allLoaded: false, //是否宣布加载完
      bottomDistance:120
    };
  },
  mounted() {
    this.getPageData(false);
  },

  methods: {
    //获取页面数据
    getPageData(isScroll = true) {
      if (isScroll) {
        if (this.pagesNum >= this.maxPageNum) {
          this.pagesNum = this.maxPageNum;
          this.allLoaded = true;
          this.$toast("无更多数据");
          return;
        } else {
          this.pagesNum++;
        }
      } else {
        this.pagesNum = 1;
      }
      this.$util
        .get("user/getUserPromotionIncomeList", {
          uid: this.$store.state.userinfo.uid,
          page: this.pagesNum
        })
        .then(res => {
          this.maxPageNum = res.data.last_page;
          this.genaralizeList = res.data.data.concat(this.genaralizeList);
        });
    },
    loadBottom() {
      // 上拉加载
      this.getPageData(); // 上拉触发的分页查询
      this.$refs.loadmore.onBottomLoaded(); // 固定方法，查询完要调用一次，用于重新定位
    }
  }
};
</script>
<style lang='less' scoped>
@import url(../../assets/css/balance/generalize.less);
</style>